package com.contract.spirit.ui.order

import androidx.lifecycle.MutableLiveData
import com.contract.commonlib.base.BaseViewModel
import com.contract.commonlib.http.ext.request
import com.contract.commonlib.http.status.ResultState
import com.contract.spirit.bean.entity.GuarantOrderInfo
import com.contract.spirit.bean.entity.OrderInfo
import com.contract.spirit.func.net.rxApi

/**
 * @author: zhengjun
 * created: 2021/9/27
 * desc:
 */
class OrderViewModel : BaseViewModel() {

    var orderListRes = MutableLiveData<ResultState<List<OrderInfo>>>()
    var guarantOrderListRes = MutableLiveData<ResultState<List<GuarantOrderInfo>>>()
    var gainPayRes = MutableLiveData<ResultState<String>>()
    fun getOrderList(tab: String, currentPage: Int, exchangeType: String) {
        request(
            {
                rxApi.getOrderList(tab, currentPage.toString(), exchangeType)
            }, orderListRes,
            orderListRes.value == null
        )
    }

    fun getGuarantOrderList(exchangeType: String) {
        request(
            {
                rxApi.getGuarantOrderList(exchangeType)
            }, guarantOrderListRes,
            guarantOrderListRes.value == null
        )
    }

    fun gainPay(id: String) {
        request(
            {
                rxApi.gainPay(id)
            }, gainPayRes,
            isShowDialog = true,
            loadingMessage = true
        )
    }
}